package ACM_Brush;

import java.util.Scanner;

public class Solution032 {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String s = in.nextLine();
            System.out.println();
            System.out.println(new solution_032().longestValidParentheses(s));
        }
    }
}

class solution_032 {
    public int longestValidParentheses(String s) {
        int length = s.length();
        if (length == 0)
            return 0;
        int[] dp = new int[length]; // dp[i] 表示以 charAt(i) 结尾的括号的最长有效括号
        dp[0] = 0;
        int maxLength = 0;
        for (int i = 1; i < s.length(); i++) {
            if ('(' == s.charAt(i))
                dp[i] = 0;
            else {
                if ('(' == s.charAt(i - 1))
                    dp[i] = i - 2 >= 0 ? 2 + dp[i - 2] : 2;
                else {
                    if (i - 1 - dp[i - 1] < 0 || ')' == s.charAt(i - 1 - dp[i - 1]))
                        dp[i] = 0;
                    else
                        dp[i] = i - 1 - dp[i - 1] - 1 >= 0 ? 2 + dp[i - 1 - dp[i - 1] - 1] + dp[i - 1] : 2 + dp[i - 1];
                }
            }
            maxLength = Math.max(maxLength, dp[i]);
        }
        return maxLength;
    }
}